import useSaveAsPropsStore from '@renderer/store/CpnProps/SaveAsPropsStore'
import useGlobalLoadingStateStroe from '@renderer/store/Loading/GlobalLoadingStateStroe'

export default function useExecuteFileRename(
  callback: () => ITableDataItem[],
  emits: (event: 'update', preload: ITableDataItem[]) => void
) {
  const loadingStateStroe = useGlobalLoadingStateStroe()
  const saveAsPropsStore = useSaveAsPropsStore()

  // 执行文件 / 文件夹重命名
  function executeFileRename() {
    loadingStateStroe.actionRename(async () => {
      const res = await window.api.executeFileRename(
        JSON.parse(JSON.stringify(callback())),
        saveAsPropsStore.saveMethod,
        saveAsPropsStore.targetDir
      )
      emits('update', res)
    })
  }

  return {
    executeFileRename
  }
}
